import os
from langchain_community.llms.tongyi import Tongyi
from langchain.sql_database import SQLDatabase
db_user = "root"
db_password="tbt727303"
db_host="127.0.0.1"
db_name="langchain_demo"
db=SQLDatabase.from_uri(f"mysql+pymysql://{db_user}:{db_password}:{db_host}:{db_name}")

from langchain.chains import create_sql_query_chain

llm=Tongyi()
chain = create_sql_query_chain(llm,db)
response = chain.invoke({"question":"How many students are there"})
print(response)

result_sql = db.run(response)
print(result_sql)